xen/arm64: Don't zero BSS when booting using EFI
authorJulien Grall <julien.grall@arm.com>
Wed, 8 Feb 2017 10:48:14 +0000 (10:48 +0000)
committerStefano Stabellini <sstabellini@kernel.org>
Wed, 8 Feb 2017 23:32:02 +0000 (15:32 -0800)
commit6cc8e8708e65f42d12ff7ea02156aafc5afdb2f7
tree720741f25d37732e3b00a47b29b26cba541ba1cf
parent04dbb71096143b54f8b5e1acfce8d55150609d3f
xen/arm64: Don't zero BSS when booting using EFI

Commit 146786b "efi: create efi_enabled()" introduced a variable
efi_flags stored in BSS and used to pass information between the stub
and Xen. However on ARM, BSS is zeroed after the stub has finished to
run and before Xen is started. This means that the bits set in efi_flags
will be lost.

We were not affected before because all the variables used to pass
information between Xen and the stub are living in initdata or data.

Looking at the description of the field SizeOfRawData in the PE/COFF
header (see [1]):

"If this is less than VirtualSize, the remainder of the section is
zero-filled. Because the SizeOfRawData field is rounded but the
VirtualSize field is not, it is possible for SizeOfRawData to be greater
than VirtualSize as well. When a section contains only uninitialized
data, this field should be zero."

Both VirtualSize and SizeOfRawData are correctly set in the header (see
arch/arm/arm64/head.S) so the EFI firmware will zero BSS for us.

Therefore we don't need to zero BSS before running the EFI stub and can
skip the one between the EFI stub and Xen.

To avoid another branch instruction, slightly refactor the code. The
register x26 is allocated to hold whether BSS is skipped. The value will
be:
    - 0 when the code is running on CPU0 and EFI is not used
    - 1 when EFI is used or running on other processor than the boot one.

[1] https://msdn.microsoft.com/en-us/library/windows/desktop/ms680547(v=vs.85).aspx

Signed-off-by: Julien Grall <julien.grall@arm.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
xen/arch/arm/arm64/head.S